package handler

import (
	"context"
	"exam-app/user-srv/internal/model/service"
	pb "exam-app/user-srv/proto"
	"fmt"
)

type UserServer struct {
	pb.UnimplementedUserServer
}

func (u *UserServer) Login(ctx context.Context, req *pb.LoginRequest) (resp *pb.LoginResponse, err error) {

	account, err := service.GetUserAccount(req.Account)
	if err != nil {
		return nil, fmt.Errorf("账号不存在")
	}
	if req.Password != account.Password {
		return nil, fmt.Errorf("账号或者密码错误")
	}
	//返回响应
	return &pb.LoginResponse{Id: int32(account.ID)}, nil
}
